package com.heakey.common.util;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;
import com.heakey.common.model.PageReq;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description TODO
 * @Author Bing
 * @Date 2024/10/14 14:45
 */
public class PageUtil {

    public static <T> Page<T> toPage(PageReq pageReq){
        return Page.of(pageReq.getPageNum(), pageReq.getPageSize());
    }

    public static <T> List<T> getPageList(List<T> list){
        if(CollUtil.isEmpty(list)){
            return new ArrayList<>(0);
        }
        if(list instanceof Page){
            PageInfo<T> pageInfo = new PageInfo<>(list);
            return pageInfo.getList();
        }
        return list;
    }
}